package com.jisu.controller;


import com.jisu.common.ResultVo;
import com.jisu.pojo.Admin;
import com.jisu.service.IAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;


@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private IAdminService iadminService;

    //增：添加管理员
    @PostMapping("/addAdmin")
    public ResultVo<Admin> addAdmin(@RequestBody Admin admin) {
        admin.setCreatedTime(LocalDateTime.now());
        admin.setUpdatedTime(LocalDateTime.now());
        return iadminService.addAdmin(admin);
    }

    //删：删除管理员,传入多id
    @DeleteMapping("/deleteAdmin")
    public ResultVo deleteAdmin(@RequestParam("ids") List<Integer> ids) {
        return iadminService.deleteAdmin(ids);
    }

    //改：修改管理员
    @PutMapping("/updateAdmin")
    public ResultVo<Admin> updateAdmin(@RequestBody Admin admin) {
        return iadminService.updateAdmin(admin);
    }

    //查：查询管理员,多条件查询，模糊查询
    @PostMapping("/getAdmin")
    public ResultVo<List<Admin>> getAdmin(@RequestBody(required = false) Admin admin) {
        return iadminService.getAdmin(admin);
    }
}